<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>03-全选全不选反选.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">




</head>
<body>
	您的爱好很广泛!!!
	<br>
	<input type="checkbox" id="input" />全选/全不选
	<input type="checkbox" name="items" value="足球" />足球
	<input type="checkbox" name="items" value="篮球" />篮球
	<input type="checkbox" name="items" value="游泳" />游泳
	<input type="checkbox" name="items" value="唱歌" />唱歌
	<br>
	<input type="button" name="checkall" id="checkall" value="全选" />
	<input type="button" name="checkall" id="checkallNo" value="全不选" />
	<input type="button" name="checkall" id="check_revsern" value="反选" />

	<script type="text/javascript">
		let checkall = document.getElementById("checkall");
		checkall.onclick = ()=>{
			let items = document.getElementsByName("items");
			for (let i = 0; i < items.length; i++) {
				items[i].checked = true;

			}
		}


		//全不选
		let checkallNo = document.getElementById("checkallNo");
		checkallNo.onclick = ()=>{
			let items = document.getElementsByName("items");
			for (let i = 0; i < items.length; i++) {
				items[i].checked = false;
			}
		}

		//反选
		let check_revsern = document.getElementById("check_revsern");

		check_revsern.onclick = ()=>{
			let items = document.getElementsByName("items");
			for (let i = 0; i < items.length; i++) {
				items[i].checked = !(items[i].checked);

			}

		}

	</script>
</body>

</html>
